<?php
/**
 * 		订单导出控制器
 */

Core::load_class('init', 'admin');
require_once APP_PATH.'module/order/library/driver/getexl/get_exl.class.php';
class order_exl_control extends init_control {

	public function _initialize() {
		parent::_initialize();
		$this->supplier_table = $this->load->table('supplier/supplier');
		$this->service = $this->load->service('order_exl');
    $this->supplier_service = $this->load->service('supplier/supplier');
	}

	/* 订单批量导出 */
   


	public function index(){
		if (checksubmit('dosubmit')) {   
			$starttime = empty($_GET['starttime'])? '0' : addslashes(strtotime($_GET['starttime']));
			$endtime = empty($_GET['endtime'])? '9999999999' : addslashes(strtotime($_GET['endtime']));	
      $status = $_GET['status'];
      $supplier_name = $_GET['supplier_name'];
      $sqlmap['C.time'] =array('between',"$starttime,$endtime");
      $sqlmap['seller_id'] = '';
      if($_GET['id'] !== ''){
        $sqlmap['seller_id'] = $_GET['id'];
      }else{
        unset($sqlmap['seller_id']);
      }

     if( $status !== ''){
     $sqlmap[] = $this->service->build_sqlmap($status);
     }
     

          
           /*按指定条件查找数据*/
            $data = $this->service->message($sqlmap,$supplier_name);
            
            /*导出订单*/
            $rowVal = array('日期','订单号','支付类型','收款订单号','收货人','收货地址','电话号码','商品名称','单价','数量','金额','实付金额','运费','厂家名称','产品编号','订单状态','商品状态');
            $exl = new get_exl();
            $exl->_get_exl($rowVal,$data,$supplier_name,$status);         
		}
      $status = array(''=>'',
                      '已支付'=>0,
                      '待付款'=>1,
                      '待发货'=>2,    
                      '待收货'=>3,
                      '已完成'=>4,
                      '已取消'=>5,
                      '已删除'=>6
        );
      

		  $suppliers = $this->supplier_table->field('id,company,supplier_name')->select();
      $this->load->librarys('View')->assign('status',$status);
			$this->load->librarys('View')->assign('suppliers',$suppliers);
			$this->load->librarys('View')->display('exl');
	 }


   /**
   * [ajax_seller_name ajax查询商家名称]
   * @return [type] [description]
   */
   public function ajax_seller_name(){
    $result = $this->supplier_service->ajax_supplier($_GET['seller_name']);
    if(!$result){
      showmessage($this->supplier_service->error,'',0,'','json');
    }else{
      showmessage(lang('_operation_success_'),'',1,$result,'json');
    }
  }
}

?>